package ee.ut.math.tvt.salessystem.ui.model;

import java.util.List;

import ee.ut.math.tvt.salessystem.domain.controller.SalesDomainController;
import ee.ut.math.tvt.salessystem.domain.data.Sale;
import ee.ut.math.tvt.salessystem.domain.data.StockItem;

/**
 * Main model. Holds all the other models.
 */
public class SalesSystemModel {
    
	// Warehouse model
	private StockTableModel warehouseTableModel;

    // Current shopping cart model
    private PurchaseInfoTableModel currentPurchaseTableModel;

	// Puchase history model
	private PurchaseHistoryTableModel purchaseHistoryTableModel;

    /**
     * Construct application model.
     * @param domainController Sales domain controller.
     */
    public SalesSystemModel(SalesDomainController domainController) {

        warehouseTableModel = new StockTableModel();
		currentPurchaseTableModel = new PurchaseInfoTableModel();
		purchaseHistoryTableModel = new PurchaseHistoryTableModel();

		// Load data from the database

		List<StockItem> stockItems = domainController.getAllStockItems();
		warehouseTableModel.populateWithData(stockItems);

		populatePurchaseHistoryTable(domainController);
	}

	public void populatePurchaseHistoryTable(SalesDomainController domainController) {
		List<Sale> sales = domainController.getAllSales();
		purchaseHistoryTableModel.populateWithData(sales);
	}

    public StockTableModel getWarehouseTableModel() {
        return warehouseTableModel;
    }

    public PurchaseInfoTableModel getCurrentPurchaseTableModel() {
        return currentPurchaseTableModel;
    }

	public PurchaseHistoryTableModel getPurchaseHistoryTableModel() {
		return purchaseHistoryTableModel;
	}

	public void setPurchaseHistoryTableModel(PurchaseHistoryTableModel purchaseHistoryTableModel) {
		this.purchaseHistoryTableModel = purchaseHistoryTableModel;
	}
    
}
